<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserInfo extends Model
{
    public $fillable = [
		'user_id',
            //openid
            'open_id',
            //当前绑定设备号码
            'current_device_id',
            //微信昵称
            'wx_nickname',
            //微信头像
            'wx_head_img_url',
            //是否关注
            'is_subscribe',
            //性别
            'wx_sex',
            //市
            'wx_city',
            //省
            'wx_province',
            //国家
            'wx_country',
            //语言
            'wx_language',
            //关注时间
            'subscribe_time',
            //用户姓名
            'name',
            //安装地址
            'installation_address',
            //手机
            'phone',
            'sex',
    ];

    public $primaryKey = 'user_id';

    // protected $appends = [
    //     'sex_description',
    // ];

    // const SEX_MALE = 1;
    // const SEX_FEMALE = 2;

    // public static $_SEX_DESCRIPTION = [
    //     0 => '',
    //     self::SEX_FEMALE => '女',
    //     self::SEX_MALE => '男',
    // ];

    // public function getSexDescriptionAttribute($value)
    // {
    //     if(array_key_exists('sex', $this->attributes))
    //     {
    //         return self::$_SEX_DESCRIPTION[$this->attributes['sex']];
    //     }
    // }

    public function device(){
      return $this->belongsTo('App\Models\Device', 'current_device_id');
    }

    public function afterServices()
    {
        $this->hasMany('App\Models\AfterService', 'user_id', 'user_id');
    }

    public function chargeRecords()
    {
        $this->hasMany('App\Models\chargeRecord', 'user_id', 'user_id');
    }

}
